导航菜单

What Is an API Endpoint?

API endpoints are usually found in an API’s documentation, which is where developers put API information such as what type of requests an API will accept and how requests should be formatted. Ideally, this documentation also includes a list of all available API endpoints and a short description of their functionalities.

In a REST API (a software architectural style frequently used for web applications) context, the process looks like this:

The process starts when an API client sends a resource request (API call) to the corresponding API endpoint. Endpoints are accessed by using HTTP request methods such as POST, GET, PUT, PATCH and DELETE. These methods indicate the action that the client is looking to take on the specified resource.

For example, if a client is looking to retrieve a list of Olympic medal totals for a certain year from the hypothetical database Olympicfacts.com, a GET request is sent to the following endpoint URL: https://api.olympicfacts.com/v1/{year}

This request would return a list of Olympic medal totals by country. (v1 in our hypothetical endpoint indicates the version of the API, a common practice in API versioning.) If the client wanted a total for a specific country in a given year, an identifier would be added to the base URL:  https://api.olympicfacts.com/v1/year/{id}

In this example, the identifier {id} is used to indicate which country the client is looking to receive information about.

In addition, a request might include:

Headers: Headers can provide additional information about the request, such as an Accept header that specifies accepted media typesParameters: Query parameters can be added to the base URL or in the request body to further filter search criteria or add other specifications.Request body: A request body includes the data needed to create or modify a resource. For example, if the request is to create a new blog (POST request), the content of the new blog would be included in the request body.

Once the server authenticates the request and validates the input, it retrieves the requested data and returns the response to the client. Many organizations use API gateways to execute these functions and manage API traffic flow.

相关推荐: